package edu.whu.assignment8.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import edu.whu.assignment8.dataobject.Product;
import edu.whu.assignment8.dataobject.dto.ProductDto;
import org.apache.ibatis.annotations.*;

@Mapper
public interface ProductMapper extends BaseMapper<Product> {

    @Select("select * from product where pid = #{pid};")
    @Results({@Result(id = true, property = "pid", column = "pid"),
              @Result(property = "image", column = "image"),
              @Result(property = "pname", column = "pname"),
              @Result(property = "price", column = "price"),
              @Result(property = "supplierList", column = "pid",
                      many = @Many(select = "edu.whu.assignment6.mapper.SupplierMapper.findAllByPid"))
    })
    ProductDto findProductAndSuppliersByPid(int pid);
}

/*
* @Results注解：只有两个属性，id和value，id作为该注解的唯一标识，value值为@Result数组
* 查询出的列和Product中属性信息的映射关系是在@Results中value属性的@Result注解进行配置的
* @Result注解：id标识该字段是否为主键，column对应数据库中列名，property对应类中的属性名，javaType对应数据类型
*   @One注解标识是一对一配置，@Many注解标识一对多配置（select标识要执行的方法，fetchType标识是及时加载还是懒加载）
* */
